#Harris 1976 ABC Presidential Election Survey, study no. 2624A-1
## packages 

require("dplyr")
require("readstata13")

## set working directory to
## replication folder


## download data
survey <- read.dta13("Harris_Data/Harris 1976 ABC Presidential Election Survey, study no. 2624A-1/harris_s2624a1_spss.dta")

## pid
survey$pid <- c(1:nrow(survey))
class(survey$pid)

## study number
survey$study <- as.character(2434)
class(survey$study)

## year
survey$year <- 1974
class(survey$year)

## geographpic data
summary(survey$S13)
survey$urban <- as.character(survey$S13)
summary(survey$urban)

## region 
summary(survey$S11)
survey$region <- as.character(survey$S11)

## respondent name
survey$hh <- NA

## inequality increasing
summary(survey$Q11A_2)
survey$inequality <- as.character(survey$Q11A_2)
table(survey$inequality)

## inequality variable version
survey$inequality.variable <- 1
class(survey$inequality.variable)


## union 
survey$union.self <- as.character(survey$F2_1)
survey$union.other <- as.character(survey$F2_2)
summary(survey$union.self)
summary(survey$union.other)

## survey items asked separately
## so combining "not sure" 
survey[survey$F2_4 == "Yes", c("union.self", "union.other", "F2_3")]
survey$union.self[survey$F2_4 == "Yes"] <- "Not Sure" 
survey$union.other[survey$F2_4 == "Yes"] <- "Not Sure" 

## Are you employed? what kind of employment?
summary(survey$F3A)
survey$employed <- as.character(survey$F3A)
table(survey$employed)

## employed self
survey$employed.self <- NA

## Occupation
summary(survey$F3B)
survey$occupation <- as.character(survey$F3B)
table(survey$occupation)

## occ self 
survey$occupation.self <- NA

## household size
survey$hhsize <- NA

## Education
summary(survey$F1)
survey$educ <- as.character(survey$F1)
table(survey$educ)

## Income
summary(survey$F4)
survey$income <- as.character(survey$F4)
table(survey$income)

## Age 
summary(survey$Q1D)
survey$age <- as.character(survey$Q1D)
summary(survey$age)

## race
summary(survey$F6)
survey$race <- as.character(survey$F6)
summary(survey$race)

## politics 
summary(survey$Q1C)
survey$party <- as.character(survey$Q1C)

## ideology
summary(survey$Q1K)
survey$ideology <- as.character(survey$Q1K)
summary(survey$ideology)

## gender
summary(survey$F7)
survey$gender <- as.character(survey$F7)
table(survey$gender)

## religion
summary(survey$F5)
survey$religion <- as.character(survey$F5)
summary(survey$religion)

## factuals
survey$factual1 <- NA
survey$factual2 <- NA
survey$factual3 <- NA

## alienation index
survey$dontcare <- as.character(survey$Q11A_1)
survey$dontcount <- as.character(survey$Q11A_3)
survey$leftout <- as.character(survey$Q11A_4)

## question place
survey$question_place <- "after party"

# subset
survey_2624A1 <- survey[,c("pid", "study", "year", "urban", "region", "hh",
                           "inequality", "inequality.variable", "union.self", "union.other",
                           "employed", "employed.self", "occupation", "occupation.self", "hhsize", "educ", "income", 
                           "age", "race", "party", "ideology", "gender", "religion",
                           "factual1", "factual2", "factual3", "dontcare", "dontcount", "leftout",
                           "question_place")]

#saveRDS(survey_2624A1, file = "Harris_Data/survey_2624A1.rds")



